package net.begincode.searchCommon.bean;

import net.begincode.searchCommon.enums.CommonResponse;
import net.begincode.searchCommon.enums.ResponseEnum;

import java.text.MessageFormat;

/**
 * @author hlj~宇晗
 * @create 2017-03-26 23:54
 **/
public class Response {

	private String code;
	private String msg;
	//将页面信息page绑定到data里面。
	private Object data;

	public Response(String code, String msg, Object data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
	public Response(String code,String msg){
		this.code = code;
		this.msg = msg;
	}
	//将数据封装到data里
	public static Response success() {
		return new Response(CommonResponse.SUCCESS.getCode(), CommonResponse.SUCCESS.getMessage());
	}
	public static Response success(Object data){
		return new Response(CommonResponse.SUCCESS.getCode(),CommonResponse.SUCCESS.getMessage(),data);
	}
	public static Response failed(ResponseEnum status){
		return new Response(status.getCode(),status.getMessage(),null);
	}
	public static Response failed(ResponseEnum status, Object[] messages) {
		return new Response(status.getCode(), MessageFormat.format(status.getMessage(), messages), null);
	}

	public static Response failed(ResponseEnum status, Object data) {
		return new Response(status.getCode(), status.getMessage(), data);
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
}
